package com.foton.logistic.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ScrollView;

import com.foton.logistic.R;
import com.foton.logistic.base.BaseActivity;
import com.foton.logistic.listener.IOnResultListener;
import com.foton.logistic.task.DispatchTask;
import com.foton.logistic.task.ShowLoadTask;
import com.foton.logistic.task.TaskConstant;
import com.foton.logistic.util.BaseConstant;
import com.foton.logistic.util.OptionUtil;
import com.foton.logistic.util.net.HttpUtil;

import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by macbook on 17/12/7.
 */

public class SetPasswordActivity extends BaseActivity {

    @InjectView(R.id.ft_ui_et_new_password)
    EditText ftUiEtNewPassword;
    @InjectView(R.id.ft_ui_scrollView)
    ScrollView ftUiScrollView;
    private Intent intent;
    private String code;
    private String telephone;
    private String newpassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ft_ui_set_password);
        ButterKnife.inject(this);
    }

    @Override
    public void init() {
        setBackLayoutVisibility(View.VISIBLE);
        setTitleText("设置密码");
        setTitleTextVisibility(View.VISIBLE);
        intent = getIntent();
        code = intent.getStringExtra("code");
        telephone = intent.getStringExtra("telephone");


    }

    @OnClick(R.id.ft_ui_complete)
    public void onViewClicked() {
        newpassword = ftUiEtNewPassword.getText().toString().trim();
        String url = BaseConstant.forgetPassword;
        Map<String, Object> argMap = HttpUtil.getEncryMap(this);
        argMap.put("telphone", telephone);
        argMap.put("smsCode", code);
        argMap.put("newPassword", newpassword);
        ShowLoadTask task = new ShowLoadTask(this, taskTag, ftUiScrollView, loadLayout, "", true, null, url, argMap, TaskConstant.POST);

        task.setiOnResultListener(new IOnResultListener() {


            @Override
            public void onOK(DispatchTask task) {
                Intent intent=new Intent(SetPasswordActivity.this,LoginActivity.class);
                startActivity(intent);
                OptionUtil.addToast(SetPasswordActivity.this, "设置成功");
                finishSelf();

            }

            @Override
            public void onError(DispatchTask task) {
                OptionUtil.addToast(SetPasswordActivity.this, "设置失败");

            }

            @Override
            public void onDone(DispatchTask task) {

            }
        });
        task.execute();
    }
}
